Repository navigation
Give a cppia member field declared Bool its boolean storage - #1367
Merged
tobil4sk merged 3 commits intoNov 5, 2026
Merged
Conversation
Contributor
Author
|
Extended the tests. |
tobil4sk
reviewed
Aug 18, 2026
tobil4sk
reviewed
Aug 27, 2026
tobil4sk
approved these changes
Aug 30, 2026
tobil4sk
left a comment
Member
There was a problem hiding this comment.
Looks good to me now, the new code is cleaner and more consistent with the static implementation:
hxcpp/src/hx/cppia/CppiaVars.cpp
Line 99 in 10f73c5
dimensionscape
pushed a commit
to openfl/libhxcpp
that referenced
this pull request
Oct 15, 2026
A script class laid out its members by expression type alone, so a Bool member got int storage while a Bool static got Bool storage, and reading the member into Dynamic gave an Int. HaxeFoundation/hxcpp#1367 Fixes #21
dimensionscape
added a commit
to openfl/libhxcpp
that referenced
this pull request
Oct 15, 2026
Cppia holds a Bool as an int and boxes it as Bool only where the expression says it is one. Calls through the vtable, closures and property accessors boxed their result by the int type alone, so a Bool they returned reached Dynamic as an Int: Std.isOfType(x, Bool) was false and it printed and serialized as 1. They now box by the declared return type, as direct calls already did. Found by the stricter Bool comparison of HaxeFoundation/hxcpp#1009, which these Ints failed, alongside the Bool members of HaxeFoundation/hxcpp#1367.
dimensionscape
pushed a commit
to openfl/libhxcpp
that referenced
this pull request
Oct 15, 2026
Type.typeof on a Bool member field and a Bool static read by name must both give TBool. HaxeFoundation/hxcpp#1367
dimensionscape
pushed a commit
to openfl/libhxcpp
that referenced
this pull request
Oct 15, 2026
Type.typeof on a Bool member field and a Bool static read by name must both give TBool. HaxeFoundation/hxcpp#1367
dimensionscape
pushed a commit
to openfl/libhxcpp
that referenced
this pull request
Oct 15, 2026
Type.typeof on a Bool member field and a Bool static read by name must both give TBool. HaxeFoundation/hxcpp#1367
dimensionscape
pushed a commit
to openfl/libhxcpp
that referenced
this pull request
Oct 15, 2026
Type.typeof on a Bool member field and a Bool static read by name must both give TBool. HaxeFoundation/hxcpp#1367
dimensionscape
pushed a commit
to openfl/libhxcpp
that referenced
this pull request
Oct 15, 2026
Type.typeof on a Bool member field and a Bool static read by name must both give TBool. HaxeFoundation/hxcpp#1367
dimensionscape
added a commit
to openfl/libhxcpp
that referenced
this pull request
Oct 15, 2026
Cppia holds a Bool as an int and boxes it as Bool only where the expression says it is one. Calls through the vtable, closures and property accessors boxed their result by the int type alone, and the JIT stored a Bool argument of a script enum as an Int variant, so those Bools reached Dynamic as an Int: Std.isOfType(x, Bool) was false and they printed and serialized as 1. The calls now box by the declared return type, as direct calls already did, and the JIT stores a Bool enum argument as a Bool. Found by the stricter Bool comparison of HaxeFoundation/hxcpp#1009, which these Ints failed, alongside the Bool members of HaxeFoundation/hxcpp#1367.
dimensionscape
pushed a commit
to openfl/libhxcpp
that referenced
this pull request
Oct 15, 2026
Type.typeof on a Bool member field and a Bool static read by name must both give TBool. HaxeFoundation/hxcpp#1367
dimensionscape
pushed a commit
to openfl/libhxcpp
that referenced
this pull request
Oct 15, 2026
Type.typeof on a Bool member field and a Bool static read by name must both give TBool. HaxeFoundation/hxcpp#1367
dimensionscape
pushed a commit
to openfl/libhxcpp
that referenced
this pull request
Oct 15, 2026
Type.typeof on a Bool member field and a Bool static read by name must both give TBool. HaxeFoundation/hxcpp#1367
Member
|
I refactored the cppia tests in #1440. The changes there allow for a simpler test in this PR, here is what I would suggest: --- a/test/cppia/cases/client/TestClient.hx
+++ b/test/cppia/cases/client/TestClient.hx
@@ -6,6 +6,8 @@ class TestClient extends Test {
public static var clientBool2 = true;
public static var clientBool3 = false;
+ var memberBool = true;
+
function testThread() {
// See if it compiles
Assert.notNull(sys.thread.Thread.current());
@@ -55,6 +57,9 @@ class TestClient extends Test {
var hostBools = HostBase.hostBool0 + "/" + HostBase.hostBool1 + "/" + HostBase.hostBool2 + "/" + HostBase.hostBool3;
var clientBools = clientBool0 + "/" + clientBool1 + "/" + clientBool2 + "/" + clientBool3;
Assert.equals(hostBools, clientBools);
+
+ Assert.same(Type.ValueType.TBool, Type.typeof(clientBool0));
+ Assert.same(Type.ValueType.TBool, Type.typeof(memberBool));
}
function testIssue926() {
|
CppiaVar::linkVarTypes has two forms. The static form asks fieldStorageFromType, which answers fsBool for Bool. The member form switches on exprType instead, and TypeData::link has already mapped Bool onto etInt by the time it runs, so the field is laid out as fsInt and reads back through reflection as 1 rather than true. The member form now asks fieldStorageFromType as well. The slot stays the size of an int, leaving the layout and the AlignOffset call above it unchanged.
Every storage fieldStorageFromType returns maps onto an exprType with the same size, so the switch collapses to a table lookup and the offsets stay byte-identical.
tobil4sk
force-pushed
the
fix-cppia-bool-member-storage
branch
from
November 4, 2026 11:29
59c19e3 to
eebb510
Compare
Member
|
Thank you! |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
The problem
A class member declared
Boolin a cppia module gets an integer slot, so reading it back throughreflection gives you
1instead oftrue. A static field of the same declared type, in the samemodule, gives you
true:Conditions and comparisons still work, since they are happy with the integer. Anything that looks at
the value itself does not.
Why
CppiaVar::linkVarTypeshas two forms:fieldStorageFromType, which has a case forBooland returnsfsBool.exprTypeinstead. By the time it runs,TypeData::linkhasalready mapped the
Booltype name toetInt, so the field ends up asfsInt.That is why the two fields above disagree.
The fix
In
src/hx/cppia/CppiaVars.cpp, the member form now callsfieldStorageFromTypetoo:The slot is still int sized, so the layout and the
AlignOffsetcall above it do not change.Test
test/cppiacovers it.ClientBoolFieldinClient.hxholds aBoolmember and aBoolstatic,and
testBoolMemberStorageincases/TestCommon.hxreads both back throughReflect.field.Without the fix that test fails with
Member Bool did not read back as a boolean, and the staticassertion beside it still passes, which is the pair that shows the two forms disagreeing. Same result
with or without
-jit.Reproducing by hand
Script.hx, built withhaxe -m Script --cppia script.cppia:Load it from a host built with
-D scriptable, usingcpp.cppia.Module.fromData(bytes).boot(), and callScript.runthrough reflection.member 1, static truemember true, static trueSame result with the JIT on or off, since the storage is decided at link time.
Let me know if I got anything wrong!